<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>曾经推荐过候选人列表</title> 
    <style type="text/css">
    	#search{
    		width: 72px; 
    		background-color:#e5e5e5;
    	}
    </style>
</head>
<body>
<div class="ui segment" id="n-page">

&nbsp;
<c:choose>
    <c:when test="${recommends == null or fn:length(recommends)==0 }">
    <br>
        您还没有推荐过任何职位
    </c:when>
    <c:otherwise>
    <div>
    	<label>手机号&nbsp;:&nbsp;</label>
	    <div class="ui action left icon input">
	    	<i class="search icon"></i>
	    	<input type="text" name="phone" id="phone" placeholder="search phone" value="" >
	    	<div class="ui button" id="search" >搜索</div>
	    </div>
    </div>
   <div class="list-row" style="margin-top:10px;">
        <div class="list-title-1-1">
            职位
        </div>
        <div class="list-title-1-2">
            公司
        </div>
        <div class="list-title-1-3">
            推荐奖金 
        </div>
    </div>
    <form id="recListForm" action="${ctx}/wechat/headhunter/batchRecommend.do" method="post">
    <div id="row-data">
    
    <c:forEach items="${recommends}" var="rd" varStatus="status"> 
    <div class="position" >
    <div class="list-row job-title" data-position-id="${rd.jobid}">
        <div class="list-position-1-1">
            <input type="hidden" id ="rdJob" value="${rd.jobid}">
            ${rd.jobname}
        </div>
        <div class="list-position-1-2">
            ${rd.companyname}
        </div>
        <div class="list-position-1-3">
            ${rd.jobreward}
        </div> 
    </div>
    <c:forEach items="${rd.recommendedPerson}" var="ps" >
    
    <div class="list-row">
     <input type="hidden" name="recs[${status.index}].recId" value="${ps.id}"/>
     <input type="checkbox" name="checkedId" style="width:17px;height:17px;margin-top:6px;" class="recId-${ps.id}"  value="${ps.id}">
     <input type="hidden" class="jobId-${ps.id}" name="recs[${status.index}].jobId" value="${jobId}">
     <input type="hidden" class="personId-${ps.id}" name="recs[${status.index}].personId" value="${ps.personid}">
     <input type="hidden" class="phone-${ps.id}" name="recs[${status.index}].phone" value="${ps.phone}">
	 <input type="hidden" class="name-${ps.id}" name="recs[${status.index}].name" value="${ps.name}">
	 <input type="hidden" class="roleId-${ps.id}" name="recs[${status.index}].roleId" value="${ps.roleId}">
	 <input type="hidden" class="cityId-${ps.id}" name="recs[${status.index}].cityId" value="${ps.cityId}">
	 <input type="hidden" class="cityName-${ps.id}" name="recs[${status.index}].cityName" value="${ps.cityName}">
	 <input type="hidden" class="age-${ps.id}" name="recs[${status.index}].age" value="${ps.age}">
	 <input type="hidden" class="workage-${ps.id}" name="recs[${status.index}].workage" value="${ps.workage}">
	 <input type="hidden" class="inservice-${ps.id}" name="recs[${status.index}].inservice" value="${ps.inservice}">
	 <input type="hidden" class="companyName-${ps.id}" name="recs[${status.index}].companyName" value="${ps.companyname}">
	 <input type="hidden" class="companyid-${ps.id}" name="recs[${status.index}].companyid" value="${ps.companyid}">
        <div class="list-candid-1-1">
            ${ps.name}
        </div>
        <div class="list-candid-1-2">
            <c:choose>
                <c:when test="${ps.status == 0 }">
                    等待邀请
                </c:when>
                <c:when test="${ps.status == 1 }">
                    推荐中
                </c:when>
                <c:when test="${ps.status == 2 }">
                    推荐成功
                </c:when>
                <c:otherwise>
                    推荐失败
                </c:otherwise>
            </c:choose>
        </div>
    </div>
    </c:forEach>
    </div>
    </c:forEach>
    </div>
    </c:otherwise>
	</c:choose>
	
 	<div class="ui segment" id="btn-next2">
        <input class="fluid ui button" id="tuijianClick" value="推荐他人" type="submit"/>
    </div>
    
    </form>
</div>


<!-- 测试用，正式发布关闭 
<div id="testid">
点击获取更多数据
</div> 
-->
<input type="hidden" name="lastposition" id="lastposition" value="${fn:length(recommends)}"/> 
<input type="hidden" name="hasmoredata" id="hasmoredata" value="yes"/> 


<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">
	wx.config({
	    debug: false, 
	    appId: "${config.appid}",  
	    timestamp: ${config.currenttimestamp},  
	    nonceStr: "${config.nonceStr}", 
	    signature: "${config.signatureStr}", 
	    jsApiList: ['checkJsApi',
	        'onMenuShareTimeline',
	        'onMenuShareAppMessage',
	        'onMenuShareQQ',
	        'onMenuShareWeibo',
	        'showOptionMenu']  
	});
    var datasource = {
        moredata: function() {
            var getUrl = '${ctx}/wechat/headhunter/recommend/moreRecommend.do';
            var offset  = $('#lastposition').val();
            var hasmore = $('#hasmoredata').val();

            getUrl += "?offset=" + offset;

            if(hasmore != "yes"){
                alert("已经没有更多数据了");
                return false;
            }

            var that = this;

            $.ajax({ 
                    url: getUrl, 
                    type: "GET", 
                    success: function(data, status){ 
                        if(data.errorcode == 0) {
                            that.appenddata(data);
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            location.href = errorUrl;
                        }
                    }, 
                    error: function(){ 
                        alert("服务出错，请稍后尝试"); 
                    } 
            });
        },

        appenddata:function(data) {
            var offset = parseInt($('#lastposition').val());
            var divstring = "";
            var recommends = data.recommends;

            var count = recommends.length;
            offset += parseInt(count);
            $('#lastposition').val(offset);
            if(count <10) {
                $('#hasmoredata').val('no');
            }

			var initNum=${initNum};
			$.each(recommends,function(i,rd){
			    var rd = recommends[i];
			    divstring+="<div class='position'>";
			    divstring+="   <div class='list-row job-title' data-position-id='"+rd.jobid+"'>";
			    divstring+="      <div class='list-position-1-1'><input type='hidden' id='rdJob' value='"+rd.jobid+"'>"+rd.jobname+"</div>";
			    divstring+="      <div class='list-position-1-2'>"+rd.companyname+"</div>";
			    divstring+="      <div class='list-position-1-3'>"+rd.jobreward+"</div>";
			    divstring+="   </div>";

			    var startNum=initNum+i;
			    $.each(rd.recommendedPerson,function(index,ps){
			        divstring+="<div class='list-row'>"
			                   +" <input type='checkbox' style='width:17px;height:17px;margin-top:6px;' class='recId-"+ps.id+"' value='"+ps.id+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].recId' value='"+ps.id+"' />"              
			                   + " <input type='hidden'  name='recs["+ startNum +"].jobId'      class='jobId-" + ps.id + "' value='" + ps.jobId + "'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].personId'    class='personId-"+ps.id+"'       value='"+ps.personId+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].phone'       class='phone-"+ps.id+"'          value='"+ps.phone+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].name'        class='name-"+ps.id+"'           value='"+ps.name+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].roleId'      class='roleId-"+ps.id+"'         value='"+ps.roleId+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].cityId'      class='cityId-"+ps.id+"'         value='"+ps.cityId+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].cityName'    class='cityName-"+ps.id+"'       value='"+ps.cityName+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].age'         class='age-"+ps.id+"'            value='"+ps.age+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].workage'     class='workage-"+ps.id+"'        value='"+ps.workage+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].inservice'   class='inservice-"+ps.id+"'      value='"+ps.inservice+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].companyname' class='companyname-"+ps.id+"'    value='"+ps.companyname+"'>"
			                   +" <input type='hidden'   name='recs["+startNum+"].companyid'   class='companyid-"+ps.id+"'      value='"+ps.companyid+"'>"
			                 +"<div class='list-candid-1-1'>"+ps.name+"</div>"
			                 +"<div class='list-candid-1-2'>";
			        if(ps.status == 0){
			            divstring+="等待邀请";
			        }
			        else if(ps.status == 1){
			            divstring+="推荐中";
			        }
			        else if(ps.status == 2){
			            divstring+="推荐成功";
			        }
			        else {
			            divstring+="推荐失败";
			        }           

			        divstring+="</div>";
			        divstring += "</div>";
			    });

			    divstring+="</div>";
			});


            var newdata = $(divstring);
            $('#row-data').append(newdata);
        }
    };

    $(document).ready(function() {
    	
    	$("#search").click(function(){
    		
            var phone = $("#phone").val();
            if(!phone || phone =="") {
              alert("您必须输入手机号码");
              return false;
	        }

            var that = this;

            var postUrl = '${ctx}/wechat/headhunter/existPhone.do';
            var param = {};
            param['phone']  = phone;

            $.ajax({ 
                url: postUrl, 
                type: "POST", 
                data: param,
                success: function(data) { 
                    if(data.errorcode=="0"){
                    	alert(data.msg);
                        return;
                    }else{
                        alert(data.msg);
                        return;
                    }
                }, 
                error: function(){ 
                    alert("服务出错，请稍后尝试"); 
                    $(that).removeClass('disabled');
                } 
            });
    		
    	});    	
    	
        wx.ready(function() { 
            $(window).scroll(function() { 
                if($(window).scrollTop() == $(document).height() - $(window).height()) {
                    datasource.moredata();
                } 
            });

            $("#row-data").on(".job-title","click",function(){
				var positionid = $(this).attr('data-position-id');
                var getUrl = '${ctx}/wechat/headhunter/recommend/toView.do?jobid='+positionid;
				location.href = getUrl;
            });

            $('#testid').on('click', function(){
                datasource.moredata();
            });
            
            wx.onMenuShareAppMessage({
                title: 'Headoffer--专业招聘平台----推荐有奖！',  
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg',  
                type: 'link'
            });

            wx.onMenuShareTimeline({
                title: 'Headoffer--专业招聘平台----推荐有奖！',  
                desc: '搭起企业和专业猎头的桥梁，为企业招募英才。',  
                link: 'http://www.tiaonali.com${ctx}/wechat/hunter/shareservice.page',  
                imgUrl: 'http://www.tiaonali.com${ctx}/resources/images/sharelogo.jpg'
            });

            wx.showOptionMenu();
        });
    });

</script>
</body>
</html>